package com.yuma.springshiroredisthymeleaf.common;

import lombok.Data;

import java.io.Serializable;

@Data
public class ResultInfo<T> implements Serializable {
    private String code;  //代码
    private String message; //消息
    private T result;   //结果

    public static ResultInfo success() {
        return success(null);
    }

    public static <T> ResultInfo<T> success(T data) {
        ResultInfo<T> rb = new ResultInfo<>();
        rb.setCode(ResultEnum.SUCCESS.getCode());
        rb.setMessage(ResultEnum.SUCCESS.getMsg());
        rb.setResult(data);
        return rb;
    }

    public static ResultInfo  error(String code, String message) {
        ResultInfo rb = new ResultInfo();
        rb.setCode(code);
        rb.setMessage(message);
        rb.setResult(null);
        return rb;
    }

    public static ResultInfo error(String message) {
        ResultInfo rb = new ResultInfo();
        rb.setCode("-1");
        rb.setMessage(message);
        rb.setResult(null);
        return rb;
    }
}